package com.example.testapplication;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

public class DialogActivity extends Dialog implements View.OnClickListener{
    private TextView btnCancel,btnConfirm;


    private IOnCancelListener cancelListener;
    private IOnConfirmListener confirmListener;

    public void setCancel(IOnCancelListener cancelListener){
        this.cancelListener = cancelListener;
    }

    public void setConfirm(IOnConfirmListener confirmListener) {
        this.confirmListener = confirmListener;
    }

    public DialogActivity(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
//
        btnCancel = findViewById(R.id.btnCancel);
        btnConfirm = findViewById(R.id.btnConfirm);

        btnCancel.setOnClickListener(this);
        btnConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View view){
        switch (view.getId()){
            case R.id.btnCancel:
                if (cancelListener!=null){
                    cancelListener.onCancel(this);
                }
                dismiss();
                break;
            case R.id.btnConfirm:
                if (confirmListener!=null){
                    confirmListener.onConfirm(this);
                }
                dismiss();
                break;
            default:
                break;
        }

    }

    public interface IOnCancelListener{
        void onCancel(DialogActivity dialog);
    }
    public interface IOnConfirmListener{
        void onConfirm(DialogActivity dialog);
    }


}
